import os

def modify_txt_file(input_file, output_file):
    # 定义映射关系
    mapping = {'0':'2','1':'1','2':'3','3':'4','4':'5','5':'6','6':'7','7':'8','8':'9','9':'10','10':'0'} # 类别2修改为1,4修改为2以此类推

    with open(input_file, 'r') as f:
        lines = f.readlines()

    modified_lines = []
    for line in lines:
        parts = line.strip().split()
        if parts[0] in mapping:
            parts[0] = mapping[parts[0]]
        modified_line = ' '.join(parts) + '\n'
        modified_lines.append(modified_line)

    with open(output_file, 'w') as f:
        f.writelines(modified_lines)

if __name__ == "__main__":
    input_folder = "C:\\Users\\jxk33\\Desktop\\raw_labels" # 输入文件地址
    output_folder = "C:\\Users\\jxk33\\Desktop\\labels" # 输出地址
    cnt = 0

    for filename in os.listdir(input_folder):
        if filename.endswith(".txt"):
            input_file = os.path.join(input_folder, filename)
            output_file = os.path.join(output_folder, filename)
            modify_txt_file(input_file, output_file)
            cnt += 1
    print("modify" ,cnt)

